<template>
	<view class="wrap bggrey">
		<view class="padding">
			<view class="cz-box">
				<view class="inner">
					<view class="tit">
						提现金额
					</view>
					<view class="money-input" style="width:100%">
						<text class="unit">$</text>
						<input class="inp" type="number" @input="z_usdt_js" @propertychange="z_usdt_js"
							style="width:100%;line-height: 1.5rem;">
					</view>
					<view style="margin-top:1rem;margin-left: 1rem;">
						提现范围<text style="color: red;">最低{{MINvalue}}$</text><text
							style="color: red; margin-left: 1rem;">最高{{MAXvalue}}$</text>
					</view>
				</view>
				<view class="fcc">
					<button type="warn" class="fss" @tap="showTimeRestriction">提现</button>
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex';
	export default {
		onLoad() {
			// Hide the navigation bar
			uni.setNavigationBarTitle({
				title: ' ',

			});
		},
		onShow() {
			this.getData()
		},
		data() {
			return {
				money: null,
				uToast: '',
				startTime: new Date().setHours(10, 0, 0, 0),
				endTime: new Date().setHours(20, 0, 0, 0),
				MAXvalue:0,
				MINvalue:0,
				id: 1
			};
		},
		computed: {
			...mapGetters(['userInfo']),
			userId() {
				return this.userInfo ? this.userInfo.uid : null;
			},
			isButtonDisabled() {
				return false;
			},
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			z_usdt_js(event) {
				this.money = event.detail.value
			},
			async getData() {
				const param = {
					Id: this.id
				}
				const res = await this.$request.get('/system/withdrawal-setting/getWithdrawal', param)
              if (res.code == 200) {
                  this.MAXvalue=res.data.info.maxValue
				  this.MINvalue=res.data.info.minValue
              } 
			},
			showTimeRestriction() {

				this.$refs.uToast.show({
					type: 'loading',
					title: '',
					message: "提交中",
				})
				if (this.money === null) {
					this.$refs.uToast.show({
						type: 'error',
						icon: true,
						title: '失败主题',
						message: "请输入金额",
					})
				}else if(this.money<this.MINvalue&&this.money>this.MAXvalue){
					this.$refs.uToast.show({
						type: 'error',
						icon: true,
						title: '失败主题',
						message: `提现范围最低${this.MINvalue}$ 最高${this.MAXvalue}`,
					})
				}
				 else {
					const param = {
						userId: this.userId,
						withdrawalAmount: this.money
					}
					this.$request.post('/system/withdrawal-record/submit-withdrawal', param)
						.then(res => {
							{
								if (res.code == 200) {
									this.$refs.uToast.show({
										type: 'success',
										title: '成功主题(带图标)',
										message: res.message,
									})
								} else {
									this.$refs.uToast.show({
										type: 'error',
										icon: true,
										title: '失败主题',
										message: res.message,
									})
								}
							}
						})
						.catch(error => {
							// 处理请求失败的情况
							console.error('GET request failed:', error);
						});
				}

			},
		},
	};
</script>

<style scoped lang="scss">
	.padding {
		background-color: #ffffff;
		padding: 1rem;

		.money-input {
			.unit {
				font-size: 2.4rem;

			}

			.inp {
				font-size: 2.2rem;
				border-bottom: 1px solid;
			}

			margin-top: 1rem;
			display: flex;
			align-items: center;
		}

		.cz-box {
			.fcc {
				margin-top: 1.5rem;

				.fss {
					width: 60%;
					color: aliceblue;
				}
			}
		}
	}
</style>